{if $comments}
{literal}
<script type="text/javascript">
$(document).ready(function()
{
	var re_add_com = /add_to_node_(\d+)/;
	$(".add_comment").toggle
	(
		function()
		{
			var expanded_div_id = $(this).attr("id").replace(re_add_com,"add_comment_node_$1");
			$("#"+expanded_div_id).slideDown("fast");
			$(this).text("Свернуть форму");
			return false;
		},
		function()
		{
			var expanded_div_id = $(this).attr("id").replace(re_add_com,"add_comment_node_$1");
			$("#"+expanded_div_id).slideUp("fast");
			$(this).text("Добавить сюда комментарий");
			return false;
		}
	)
	var re_level_div = /root_(\d+)/;
	$(".view_tree").toggle
	(
		function()
		{
			var expanded_div_id = $(this).attr("id").replace(re_level_div,"node_$1");
			$("#"+expanded_div_id).slideDown("fast");
			$(this).text("свернуть ответы");
			return false;
		},
		function()
		{
			var expanded_div_id = $(this).attr("id").replace(re_level_div,"node_$1");
			$("#"+expanded_div_id).slideUp("fast");
			$(this).text("ответы на этот комментарий");
			return false;
			
		}
	);
	$("#view_price_rur").click(function(){
		$(".rur_by_meter").css("display","none");
		$(".rur").css("display","inline");
		$(".price_hint").html("(рубли)");
		$("#view_price_rur_by_meter").addClass("link");
		$("#view_price_rur_by_meter").removeClass("selected_price_view");
		$(this).removeClass("link");
		$(this).addClass("selected_price_view");
		return false;
		
	});
	$("#view_price_rur_by_meter").click(function(){
		$(".rur").css("display","none");
		$(".rur_by_meter").css("display","inline");
		$(".price_hint").html("(руб/м<sup>2</sup>)");
		$("#view_price_rur").addClass("link");
		$("#view_price_rur").removeClass("selected_price_view");
		$(this).removeClass("link");
		$(this).addClass("selected_price_view");
		return false;
		
	});
});
</script>
{/literal}
<div>
	{defun name="CommentsTree" list=$comments}
	{foreach from=$list.sub key=k item=node}
	<div class="comment_block" style="margin-left:{$node.level*10}px">
		<strong class="comment_theme">{$node.theme}</strong><p class="comment_header"><span class="comment_nickname">{$node.nickname}</span><span class="comment_date">{$node.time|date_format:"%e %B %Y в %H:%M"}</span></p>
		
		<p class="comment_content">{$node.comment|escape}</p>
		<a href="#add_comment" class="add_comment" id="add_to_node_{$node.id}">добавить сюда комментарий</a>
		{if $node.sub}
		<span> | </span><a href="#view_tree" id="root_{$node.id}" class="view_tree">ответы на этот комментарий</a>
		{/if}
		<div id="add_comment_node_{$node.id}" class="hidden">
			<form method="post" action="{$smarty.const.SITE_URL}comment.php">
				<input type="hidden" name="comment[source]" value="{$comments.source}" />
				<input type="hidden" name="comment[module]" value="{$comments.module}" />
				<input type="hidden" name="comment[obj_id]" value="{$comments.obj_id}" />
				<input type="hidden" name="comment[pid]" value="{$node.id}" />
				{if $smarty.session.site.user_id eq '0'}
				<label for="user_nickname_{$node.id}">Никнейм</label><br />
				<input id="user_nickname_{$node.id}" type="text" name="comment[nickname]" value="{$comments.nickname|escape}" class="w50" /><br />
				{else}
				<label>Никнейм</label><br />
				<strong>{$smarty.session.site.login}</strong><br />
				{/if}
				<label for="comment_theme_{$node.id}">Заголовок</label><br />
				<input id="comment_theme_{$node.id}" type="text" name="comment[theme]" value="Re: {$node.theme|escape}" class="w50" /><br />
				<label for="user_message_{$node.id}">Комментарий</label><br />
				<textarea id="user_message_{$node.id}" name="comment[comment]" class="w50" rows="5" cols="40">{$comments.comment|escape}</textarea><br />
				{if $smarty.session.site.user_id eq '0'}<label for="control_result"><img src="{$smarty.const.SITE_URL}cimg.php" /></label> <input id="control_result" type="text" name="comment[control_result]" value="" /><br />{/if}
				<input class="submit_comment" type="submit" name="submit_comment" value="Отправить" />
			</form>
		</div>
	</div>
	<br class="clear" />
	{if $node.sub}
	<div id="node_{$node.id}"{if $node.level > '0'} class="hidden"{/if}>
		{fun name="CommentsTree" list=$node}
	</div>
	{/if}
	{/foreach}
	{/defun}
</div>
<br class="clear" />
{/if}
<span class="add_comment" id="add_to_node_0">Добавить сюда комментарий</span>
<div id="add_comment_node_0" class="hidden">
	<form method="post" action="{$smarty.const.SITE_URL}comment.php">
		<input type="hidden" name="comment[source]" value="{$comments.source}" />
		<input type="hidden" name="comment[module]" value="{$comments.module}" />
		<input type="hidden" name="comment[obj_id]" value="{$comments.obj_id}" />
		<input type="hidden" name="comment[pid]" value="{$comments.pid}" />
		{if $smarty.session.site.user_id eq '0'}
		<label for="user_nickname">Никнейм</label><br />
		<input id="user_nickname" type="text" name="comment[nickname]" value="{$comments.nickname|escape}" class="w50" /><br />
		{else}
		<label>Никнейм</label><br />
		<strong>{$smarty.session.site.login}</strong><br />
		{/if}
		<label for="comment_theme">Заголовок</label><br />
		<input id="comment_theme" type="text" name="comment[theme]" value="{$comments.theme|escape}" class="w50" /><br />
		<label for="user_message">Комментарий</label><br />
		<textarea id="user_message" name="comment[comment]" class="w50" rows="5" cols="40">{$comments.comment|escape}</textarea><br />
		{if $smarty.session.site.user_id eq '0'}<label for="control_result"><img src="{$smarty.const.SITE_URL}cimg.php" /></label> <input id="control_result" type="text" name="comment[control_result]" value="" /><br />{/if}
		<input id="submit_comment" type="submit" name="submit_comment" value="Отправить" />
	</form>
</div>
